package com.qf.controller;

import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/server2")
public class Server1Controller {

    @RequestMapping(value = "/createCookie")
    public String createCookie(HttpServletResponse response){

        Cookie cookie = new Cookie("name2","server-2");
        cookie.setMaxAge(60*60*14);
        cookie.setPath("/");

        response.addCookie(cookie);
        return "ok";
    }

    @RequestMapping(value = "/getCookie")
    public String createCookie(@CookieValue(name = "name2",required = false) String cookieName,String callback){
        System.out.println("name:"+cookieName);
        return callback+"("+cookieName+")";
    }
}
